package com.dozen.commonbase.view.autopull;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.RecyclerView;

import com.dozen.commonbase.R;
import com.dozen.commonbase.bean.DozenBean;
import com.dozen.commonbase.utils.ScreenUtils;

import java.util.List;

/**
 * @author: Dozen
 * @description:
 * @time: 2021/3/29
 */
public class AutoPictureAdapter extends RecyclerView.Adapter<AutoPictureAdapter.BaseViewHolder> {
    private final List<DozenBean> mData;
    private Context context;

    public AutoPictureAdapter(List<DozenBean> list, Context context) {
        this.mData = list;
        this.context = context;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_auto_pull_picture, parent, false);
        BaseViewHolder holder = new BaseViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        DozenBean data = mData.get(position % mData.size());

        if (position == 0) {
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            layoutParams.width = ScreenUtils.getScreenWidth(context);
            layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
            holder.empty.setLayoutParams(layoutParams);
            holder.empty.setVisibility(View.VISIBLE);
        } else {
            holder.empty.setVisibility(View.GONE);
        }

        holder.iv.setBackgroundResource(R.mipmap.start_bg);
    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    class BaseViewHolder extends RecyclerView.ViewHolder {
        ImageView iv;
        ImageView empty;

        public BaseViewHolder(View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.auto_pull_picture);
            empty = itemView.findViewById(R.id.auto_pull_show_empty);
        }
    }
}